﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FaceSharp.Api;
using FaceSharp.Api.Types;
using FaceSharp.MVC.Filters;
using FaceSharp.MVC.Code.Repositories;

namespace FaceSharp.MVC.Areas.FacebookApp.Controllers
{
    public class AuthenticationController : AsyncController
    {
        /// <summary>
        /// Facebook pings this URL when a user removes your application.
        /// Cannot be a Facebook-framed page.
        /// </summary>
        [FacebookGraphApiFilter(ForceLogin = false)]
        public void RemoveCallback()
        {
            var signedRequest = (SignedRequest)System.Web.HttpContext.Current.Items["SignedRequest"];
            var userId = signedRequest.UserId;
            if(userId.HasValue)
            {
                var userRepository = new UserRepository();
                userRepository.UnInstall(userId.Value);
            }
        }
    }
}
